package com.juzishuke.margin.framework.web.feign;

import com.juzishuke.margin.framework.AppContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import static com.juzishuke.margin.framework.web.WebConstants.WEB_ROUTE_KEY_VERSION;

/**
 * @author : libo@juzishuke.com
 * @Title :
 * @Description :
 * @date : 2024/4/10 10:56
 * @since :1.0
 */
@Slf4j
public class VersionRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(final RequestTemplate template) {
        String metadataVersion = AppContext.getThreadLocal(WEB_ROUTE_KEY_VERSION);
        if(StringUtils.isNotEmpty(metadataVersion)) {
            template.header(WEB_ROUTE_KEY_VERSION,metadataVersion);
        }
    }
}
